#include <stdlib.h>
#include <chrono>
#include "all.hpp"
#include "log.h"

// define sleep ms.
#define sleepMS(x) std::this_thread::sleep_for(std::chrono::milliseconds(x))

int main(int argc, char* argv[]) {
	// init log module
	anet::log::initLog("./log", "test-net", anet::log::eLogLevel::debugLevel, 1000);

	// set log level.
	if (argc >= 2) {
		anet::log::setLogLevel(anet::log::eLogLevel(std::atoi(argv[1])));
	} else {
		anet::log::setLogLevel(anet::log::eLogLevel::debugLevel);
	}

	// set start flag
	LogAdebug("{}", "== start log server ==");

	// http server
	anet::http::CHttpServer server(2);
	// == define all kinds of post interfaces.
	server.post("/anet", [](const anet::http::HttpRes& res) ->anet::http::httpResPair {
		LogAdebug("{}", res.content);
		return { anet::http::httpStatus::OK, std::move(std::string("ok")) };
	});
	server.get("/anet", [](const anet::http::HttpRes& res) ->anet::http::httpResPair {
		LogAdebug("{}", res.content);
		return { anet::http::httpStatus::OK, std::move(std::string("ok")) };
	});
	server.start("0", 8335);
	for (;;) {
		sleepMS(1000);
	}
    
	LogAdebug("{}", "== end log server ==");

	// release log.
	anet::log::releaseLog();

	return 0;
}
